;;; init-cscope.el --- support cscope

;;; Code:
(use-package xcscope
  :defer t
  :diminish
  :bind (("C-c s s" . cscope-find-this-symbol)
         ("C-c s g" . cscope-find-global-definition))
  :commands (cscope-index-files cscope/run-pycscope)
  :init
  (progn
    (setq cscope-option-do-not-update-database t
          cscope-display-cscope-buffer nil)

    (defun cscope//safe-project-root ()
      "Return project's root, or nil if not in a project."
      (and (fboundp 'projectile-project-root)
           (projectile-project-p)
           (projectile-project-root)))

    (defun cscope/run-pycscope (directory)
      (interactive (list (file-name-as-directory
                          (read-directory-name "Run pycscope in directory:"
                                               (cscope//save-project-root)))))
      (let ((default-directory directory)
            (shell-command
             (format "%s -R -f '%s'"
                     pycscope-binary
                     (expand-file-name "cscope.out" directory))))))))

(provide 'init-cscope)
